package com.ruin.tech.ahri.controller;

import com.ruin.tech.ahri.model.dto.Notice;
import com.ruin.tech.ahri.result.Result;
import com.ruin.tech.ahri.result.ResultCode;
import com.ruin.tech.ahri.result.ResultFactory;
import com.ruin.tech.ahri.service.INoticeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @program ahri
 * @description: 公告通知信息控制器
 * @author: ruin
 * @create: 2019/11/28 15:08
 */
@Slf4j
@RestController
@RequestMapping("/notice")
public class NoticeController {

    @Autowired
    INoticeService notcieService;

    @PostMapping(value = "/edit", produces = "application/json;charset=utf-8")
    public Result editNotice(@RequestBody Notice notice) {
        try{
            notcieService.editNotice(notice);
            return ResultFactory.buildSuccessResult(notice);
        }catch (Exception e){
            log.error("编辑公告信息失败",e);
            return ResultFactory.buildFailResult(ResultCode.EDIT_NOTICE_FAIL);
        }
    }

    @PostMapping(value = "/find", produces = "application/json;charset=utf-8")
    public Result findNotice() {
        try{
            Notice notice = notcieService.findNotice();
            return ResultFactory.buildSuccessResult(notice);
        }catch (Exception e){
            log.error("查询公告信息失败",e);
            return ResultFactory.buildFailResult(ResultCode.EDIT_NOTICE_FAIL);
        }
    }

}
